package cn.linkai.hadoop.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.storm.utils.Utils;

import java.util.Properties;

public class KafkaProducerDemo {

    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("zookeeper.connect", "HA05:2181,HA06:2181,HA07:2181");
        props.put("bootstrap.servers", "HA05:9092,HA06:9092,HA07:9092");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<>(props);

        for(int i=0;i<100;i++){
            System.out.println("send:["+i+"]");
            producer.send(new ProducerRecord<>("test","["+i+"]hello word"));
            Utils.sleep(500);
        }

    }

}
